import random
import os
from rpgData import weapons, classes, spells
from checkinput import checkInput

def clear():
    os.system('cls')

class Player:
    def __init__(self, player_class, name, weapon, spell):
        """ 
        __init__ is a special method that will be called automatically when someone creates
        a player.

        Everything that starts with "self" can be used and changed 
        by all the methods/functions in the class, as long as you prefix it with "self."

        if a variable *doesn't* start with self, then it is a private variable and it can only be used
        inside the method it is declared. That works exactly like in a normal function.
        """

        self.player_class = player_class
        self.name = name
        self.weapon = weapon
        self.spell = spell

        self.health = 100
        self.gold = 0

    def is_dead(self):
        return self.health < 0

    def max_weight(self):
        return classes[self.player_class]["maxWeight"]

    def get_damage(self):
        weapon = weapons[self.weapon] # You can only use "weapon" inside get_damage
        damage = random.randint(*weapon["damage"])
        return damage


class Game:
    def __init__(self, location):
        self.current_location = location
        self.player = self.player_setup()
        self.enemy = Player("assassin", "EVIL PERSON", "titaniumDagger", "noSpell")

    def player_setup(self):
        name = input("What is your name? ")
        player_class = input("What class are you? ")
        while checkInput(player_class, ["sorcerer", "assassin", "warrior"]) == False:
            player_class = input("What is your class? ")
        if player_class == "sorcerer":
            print (name+" as a sorcerer, you are a user of magic and thus inept with weapons")
            weapon = weapons["noWeapon"]
            spell = spells["fire"]
            return Player(player_class, name, weapon, spell)
        elif player_class == "assassin":
            print (name+" as an assassin, you are stealthy, and thus best with daggers")
            weapon = weapons["ironDagger"]
            spell = spells["noSpell"]
            return Player(player_class, name, weapon[weaponName, spell])
        elif player_class == "warrior":
            print (name+" as a warrior, you are courageous and charge headfirst into battle,\
and thus best with swords")
            weapon = weapons["ironSword"]
            spell = spells["noSpell"]
            return Player(player_class, name, weapon, spell)

    def main(self):
        print("Welcome to the game, {}!".format(self.player.name))

        while not self.player.is_dead():
            enemy_damage = self.enemy.get_damage()
            self.player.health -= enemy_damage
            print("Looks like you took a hit. You lost {dmg} health. Health = {health}".format(
                    dmg=enemy_damage,
                    health=self.player.health))
        print("Ups.. you're now dead")


game = Game(location="dark forest") # Create a game object. The Game.__init__ method will be run automagically.

print("Your name is hereby {name}, your weapon is {weapon}".format(
        name=game.player.name,
        weapon=game.player.weapon[weaponName]))

game.main()  # Run the "main" method. A method is just like a function.
